package com.neusoft.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neusoft.model.ApprovalRelate;
import com.neusoft.service.ApprovalRelateService;
import com.neusoft.utils.ServerResponse;
import com.neusoft.vo.ApprovalRelateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

@RestController
@RequestMapping("/api/approval-relates")
@Api(tags = "审批设定", value = "审批管理API")
public class ApprovalRelateController {
    @Resource
    private ApprovalRelateService approvalRelateService;

    @GetMapping
    @ApiOperation("查询部门审批人")
    public ServerResponse<IPage<ApprovalRelateVO>> listApprovalRelates(
            @RequestParam(required = false) String deptName,
            @RequestParam(defaultValue = "1") @Min(1) Integer pageNum,
            @RequestParam(defaultValue = "10") @Min(1) @Max(100) Integer pageSize) {
        IPage<ApprovalRelateVO> approvalRelatePage = approvalRelateService.listApprovalRelates(deptName, pageNum, pageSize);
        return ServerResponse.success(approvalRelatePage);
    }

    @PutMapping("/{deptId}")
    @ApiOperation("修改部门审批人")
    public ServerResponse<String> updateApprover(@PathVariable Integer deptId, @RequestBody ApprovalRelate approvalRelate) throws Exception {
        approvalRelate.setDeptId(deptId);
        return  ServerResponse.success(approvalRelateService.updateApprover(approvalRelate));
    }
}